package snippet;

import java.util.ArrayList;
import java.util.List;

public class T589 {
	public static void main(String[] args) {
		List<Node> children=new ArrayList() {{
			List<Node> c=new ArrayList() {{
				
				add(new Node(5,null));
				add(new Node(6,null));
			}};
			Node n1=new Node(3,c);
			add(n1);
			add(new Node(2,null));
			add(new Node(4,null));
		}};
		Node n =new Node(1, children);
		T589 t = new T589();
		List<Integer> list = t.preorder(n);
		System.out.println(list);
	}
	 public List<Integer> preorder(Node root) {
		 List<Integer> list =new ArrayList<>();
		 put(list, root);
		 
		return list;
	        
	    }
	 public void put( List<Integer> list, Node root) {
		 if(root==null)return ;
		 
		 list.add(root.val);
		 if(root.children!=null) {
			 for ( Node c:root.children) {
				 put(list,c);
				}
		 }
		
	 }
}
